package com.liangtian.mdm.dm.jsp.common;

import com.liangtian.mdm.dm.checkRule.dao.CheckRuleDao;
import com.liangtian.mdm.dm.checkRule.model.CheckRule;
import com.liangtian.mdm.dm.common.enums.Type;
import org.apache.commons.lang3.StringUtils;
import com.liangtian.mdm.dm.config.model.AttrConfig;
import com.liangtian.mdm.dm.group.model.AttrGroup;
import com.liangtian.mdm.dm.jsp.model.GenSelectType;
import com.liangtian.mdm.dm.model.model.Model;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AddJspCreate {
    @Autowired
    CheckRuleDao checkRuleDao;

    //==============================拼写多视图页面==============================================================================
    //拼写多视图页面
    public static String searchViewType(List<GenSelectType> typeList, List<String> columList, AttrConfig attrConfig, Model model,
                                        String opaType, CheckRule checkRule, AttrGroup attrGroup) {

        String tableName = model.getTableName(); // 模型名
        String column = attrConfig.getAttrColumn().toLowerCase(); // 字段名
        String attrName = attrConfig.getAttrName(); // 属性名
        String maxLen = attrConfig.getAttrLength(); // 长度
        String type = attrConfig.getAttrType();//属性类型
        int zs = attrConfig.getAttrZs();// 获取整数位长度
        int xs = attrConfig.getAttrXs();// 获取小数位长度
        // 如果是小数位的话
        String xLen = (zs + 1 + xs) + "";// (小数的数据长度限制)
        StringBuilder sb = new StringBuilder();
        //根据某个属性的实际值，控制其他列是否显示
        String showControl = spellSelectedShezhiType(column, columList, typeList);
        if (type != null && "radioType".equals(type)) {
            sb.append(AddJspCreate.spellRadio(model, attrConfig, showControl));
        } else if (type != null && "checkBoxType".equals(type)) {
            sb.append(AddJspCreate.spellCheckBox(model, opaType, attrConfig, showControl));
        } else if (type != null && "selectList".equals(type)) {
            sb.append(AddJspCreate.spellSelectList(model, opaType, attrConfig, showControl));
        } else if (type != null && "DATE".equals(type)) {
            sb.append(AddJspCreate.spellDate(model, opaType, attrConfig, showControl));
        } else if (type != null && "popList".equals(type)) {
            sb.append(AddJspCreate.spellPopList(model, opaType, attrConfig, showControl));
        } else if (type != null && "listTree".equals(type)) {
            sb.append(AddJspCreate.spellListTree(model, opaType, attrConfig, showControl));
        } else if (type != null && "BLOB".equals(type)) {
            sb.append(AddJspCreate.spellBloB(model, opaType, attrConfig, showControl));
        } else if (type != null && "CLOB".equals(type)) {
            sb.append(AddJspCreate.spellCloB(model, opaType, attrConfig, showControl));
        } else if (type != null && "NUMBER".equals(type)) {// 类型是数字（整数 ）
            sb.append(AddJspCreate.spellNumber(model, opaType, attrConfig, showControl));
        } else if (type != null && "NUMBERM".equals(type)) {
            sb.append(AddJspCreate.spellNumberm(model, opaType, attrConfig, showControl));
        } else if (type != null && "VARCHAR2".equals(type)) { //如果是输入框
            sb.append(AddJspCreate.spellVarchar(model, opaType, attrConfig, showControl, checkRule));
        }
        //clob置为4000
        maxLen = maxLen == null ? "4000" : maxLen;
        showControl = showControl == null ? "" : showControl;
        String html = sb.toString().replace("$TABLENAME$", tableName).replace("$RN$", "\r\n")
                .replace("$COLUMN$", column).replace("$ATTRNAME$", attrName)
                .replace("$MAXLEN$", maxLen).replace("$XLEN$", xLen)
                .replace("$SHOWCONTROL$", showControl);
        return html;
    }

    //生成按钮的界面
    public static String spellButtonReplace(Model model, String opaType) {

//		String tableName = model.getTableName(); // 模型名
        StringBuilder sb = new StringBuilder();

        sb.append("");
//	      sb.append("   <div class='hr-line-dashed'></div>  $RN$");
//	      sb.append("   <div class='form-group draggable'>  $RN$");
//	      sb.append("     <div class='col-sm-5 col-sm-offset-3'>  $RN$");	
//	      sb.append("     <div style='width:100%;text-align:center;'>  $RN$");	
//	  	if("edit".equals(opaType) || "treeTabEdit".equals(opaType) ){
//	  	
//	  		sb.append("     <button id='saveButton' class='btn btn-primary' type='button' "
//	  				+ "'ng-click='EditModel()' ng-disabled='$TABLENAME$.$invalid'  style='background-color:#1ab394;border-color:#1ab394;'>保存</button>  $RN$")	;
//	  		sb.append(" <button class='btn btn-primary'  type='button' ng-click='backModel()' "
//	  				+ " style='background-color:#ccc;border-color:#ccc;'>取消</button>  $RN$ ") ;
//	  		sb.append("  <button class='btn btn-primary' type='reset' ng-click='resetModel()'  "
//	  				+ "style='background-color:#ccc;border-color:#ccc;'>重置</button>  $RN$");
//	  		
//	  	 }else if("updateEdit".equals(opaType) || "treeTabUpdateEdit".equals(opaType)){
//	  			
//	  		sb.append("     <button id='saveButton' class='btn btn-primary' type='button' "
//	  				+ "'ng-click='EditModel()' ng-disabled='$TABLENAME$.$invalid'  style='background-color:#1ab394;border-color:#1ab394;'>保存</button>  $RN$")	;
//	  		sb.append(" <button class='btn btn-primary'  type='button' ng-click='backModel()' "
//	  				+ " style='background-color:#ccc;border-color:#ccc;'>取消</button>  $RN$ ") ;
//	  		sb.append("  <button class='btn btn-primary' type='reset' ng-click='resetModel()'  "
//	  				+ "style='background-color:#ccc;border-color:#ccc;'>重置</button>  $RN$");
//	  	 }else{
////	  		 if("add".equals(opaType) || "treeTabAdd".equals(opaType) ){
//	 	  		sb.append("     <button id='saveButton' class='btn btn-primary' type='button' "
//	 	  				+ "'ng-click='saveModel()' ng-disabled='$TABLENAME$.$invalid'  style='background-color:#1ab394;border-color:#1ab394;'>保存</button>  $RN$")	;
//	 	  		sb.append(" <button class='btn btn-primary'  type='button' ng-click='backModel()' "
//	 	  				+ " style='background-color:#ccc;border-color:#ccc;'>取消</button>  $RN$ ") ;
//	 	  		sb.append("  <button class='btn btn-primary' type='reset' ng-click='resetModel()'  "
//	 	  				+ "style='background-color:#ccc;border-color:#ccc;'>重置</button>  $RN$");
//	 	  		
//	 	  	 
//	  	 }	    
//	  				
//	  				     
//	  				     
//	  	sb.append("        </div>$RN$");
//	  	sb.append("      </div>$RN$");
//	  	sb.append("   </div>$RN$");
//		String html = sb.toString().replace("$TABLENAME$", tableName).replace("$RN$", "\r\n");
//		return html;
        return sb.toString();
    }


    /**
     * 默认全部显示，勾选（默认全部未勾选）属性控制为不显示
     * 生成  ng-show='c_002==1000 || c_002==1001'
     *
     * @param column   触发列
     * @param typeList
     * @return
     */
    public static String spellSelectedShezhiType(String column, List<String> columList, List<GenSelectType> typeList) {
        if (typeList.isEmpty())
            return null;

        StringBuilder sb = new StringBuilder();
        //刘晶修改选择设置，添加多级控制
        /**1.首先判断typeList中caseColumn中有几个控制项
         * （1）caseColumn（1个控制列的话）eg:C_005
         * （2）caseColumn（2个控制列的话）eg:C_005,C_006
         */
        for (int i = 0; i < typeList.size(); i++) {
            GenSelectType gst = typeList.get(i);
            if (gst.getCaseAttrs().toLowerCase().contains(column)) {

                if ("".equals(sb.toString()))
                    sb.append("ng-show='");
//					sb.append("ng-hide='");
                if (gst.getCaseAttrs().contains(",")) {
                    String[] attrs = gst.getCaseAttrs().split(",");
                    for (int k = 0; k < attrs.length; k++) {
                        if (attrs[k].toLowerCase().equals(column)) {
                            String attr = gst.getCaseColumn().toLowerCase();
                            String value = gst.getCaseValue();
                            sb.append(attr + "!=" + value).append(" || ");//2020.12.28修改
                        }
                    }
                } else {
                    String attr = gst.getCaseColumn().toLowerCase();
                    String value = gst.getCaseValue();
                    sb.append(attr + "!=" + value).append(" || ");//2020.12.28修改
                }
            }
        }
        if (!"".equals(sb.toString())) {
            sb.delete(sb.length() - 4, sb.length());
            sb.append("'");
        }
        return sb.toString();
    }

    /**
     * Title: 普通列表模板--新增字符串替换
     *
     * @author : xiaoliu
     * @date :2016年7月26日下午2:09:12
     */
    public static String replaceAddFormat(String fileStr, Model model, String operType) {
        fileStr = fileStr.replace("@R#", "\r\n") // 替换换行
                .replace("{title}", model.getModelName()) // 替换页面导航
                .replace("{formId}", model.getTableName()) // 替换table id
                .replace("{formName}", model.getTableName()) // 替换table id
                .replace("{bodyApp}", model.getTableName()) // 替换table id
                .replace("{bodyCtr}", model.getTableName()); // 替换table id
//		if("0".equals(model.getModelType())){
//				 fileStr = fileStr.replace("{secondaryJs}", "<script src=\"${basePath}/secondary/wanda/"
//		            +model.getTableName() + "/js/" + model.getTableName() + "_add.js?t=<%=System.currentTimeMillis()%>\"></script> ");
//		 }else{
//		    	fileStr = fileStr.replace("{secondaryJs}", "");
//	 }
        fileStr = fileStr.replace("{includeJs}", model.getTableName() + "/js/" + model.getTableName() + "_" + operType + ".js");// 替换table id
        return fileStr;
    }

    /**
     * Title: 树模板  --新增字符串替换
     *
     * @author : xiaoliu
     * @date :2016年7月26日下午2:09:12
     */
    public static String replaceTreeTabAddFormat(String fileStr, Model model, String operType) {
        fileStr = fileStr.replace("@R#", "\r\n") // 替换换行
                .replace("{title}", model.getModelName()) // 替换页面导航
                .replace("{formId}", model.getTableName()) // 替换table id
                .replace("{formName}", model.getTableName()) // 替换table id
                .replace("{bodyApp}", model.getTableName()) // 替换table id
                .replace("{bodyCtr}", model.getTableName()) // 替换table id
                .replace("{AddColumn}", JspUtil.spellColumn(model, Type.ADD))
//			.replace("{ApplyColumn}", ListJspCreate.spellApplyColumn(model))
                .replace("{ApplyColumn}", JspUtil.spellColumn(model, Type.APPLY));
        if ("1".equals(model.getClassType())) {//“1”==表示是父子树   “2”==表示分类是 “0”==表示列表
            fileStr = fileStr.replace("{operColumnRep}", "<input type='hidden' id='operColumn' name='operColumn' ng-model='operColumn' value='<%= request.getParameter(\"operColumn\")%>'>");
//			<input type="hidden" name="operColumn" id="operColumn"  ng-model="operColumn"  value="<%=request.getParameter("operColumn") %>" />
        } else if ("2".equals(model.getClassType())) {
            fileStr = fileStr.replace("{operColumnRep}", "");
        }
//		 if("0".equals(model.getModelType())){
//			 fileStr = fileStr.replace("{secondaryJs}", "<script src=\"${basePath}/secondary/wanda/"
//	            +model.getTableName() + "/js/" + model.getTableName() + "_add.js?t=<%=System.currentTimeMillis()%>\"></script> ");
//	     }else{
//	    	fileStr = fileStr.replace("{secondaryJs}", "");
//	     }
        fileStr = fileStr.replace("{includeJs}", model.getTableName() + "/js/" + model.getTableName() + "_" + operType + ".js");// 替换table id
        return fileStr;
    }


    /**
     * <p>
     * Title: 生成申请页面 新增按钮所点击弹出的页面
     * </p>
     *
     * @author : xiaoliu
     * @date :2016年7月26日下午1:30:46
     */
    public static void createAddPage(String formatJspStr, String readFilePath,
                                     Model model, String operType, String appLy, Map<String, Object> result_map) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{fileSetGroups}", formatJspStr); // 将占位符替换成拼接的内容
            html = AddJspCreate.replaceAddFormat(html, model, operType); // 格式化换行等占位符
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
                html = html.replace("{mainContent}", "").replace("{mainEnd}", "").replace("{mainJsContent}", "");
                if ("updateAdd".equals(operType)) {
                    html = html.replace("{mainIdInputContent}",
                            "<input type='hidden'  id='mainId' name='mainId'  value='<%= request.getParameter(\"mainId\")%>'>\r\n "
                                    + "<input type='hidden'  id='operType' name='operType' value='<%= request.getParameter(\"operType\")%>'>\r\n ");
                } else {
                    html = html.replace("{mainIdInputContent}",
                            "<input type='hidden' id='mainId' name='mainId' value='<%= request.getParameter(\"mainId\")%>'>");
                }
            } else {
                boolean bool = (boolean) result_map.get("flag");
                if (bool) {
                    List<Model> subModelLst = (List<Model>) result_map.get("subModel");
                    Map<String, String> resMap = JspUtil.spellMainContent(model, operType, subModelLst, appLy);
                    html = html.replace("{mainContent}", resMap.get("mainHead"))
                            .replace("{mainEnd}", resMap.get("mainEnd"))
                            .replace("{mainJsContent}", resMap.get("mainJs"))
                            .replace("{mainIdInputContent}", "<input type='hidden' ng-model='mId'  id='mId'>");
                } else {
                    html = html.replace("{mainContent}", "")
                            .replace("{mainEnd}", "")
                            .replace("{mainJsContent}", "")
                            .replace("{mainIdInputContent}", "");
                }
            }
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * <p>
     * Title: 生成申请页面 新增按钮所点击弹出的页面
     * </p>
     *
     * @author : xiaoliu
     * @date :2016年7月26日下午1:30:46
     */
    public static void createTreeTabAddPage(String formatJspStr, String readFilePath,
                                            Model model, String operType, String appLy, Map<String, Object> result_map) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{fileSetGroups}", formatJspStr); // 将占位符替换成拼接的内容
            // html = AddJspCreate.replaceTreeAddFormat(html, model, operType); // 格式化换行等占位符
            html = AddJspCreate.replaceTreeTabAddFormat(html, model, operType); // 格式化换行等占位符
            if ("0".equals(model.getClassType()) && !StringUtils.isBlank(model.getMaintableId())) {
                html = html.replace("{mainContent}", "").replace("{mainEnd}", "").replace("{mainJsContent}", "");
                if ("updateAdd".equals(operType)) {
                    html = html.replace("{mainIdInputContent}",
                            "<input type='hidden'  id='mainId' name='mainId'  value='<%= request.getParameter(\"mainId\")%>'>\r\n "
                                    + "<input type='hidden'  id='operType' name='operType' value='<%= request.getParameter(\"operType\")%>'>\r\n ");
                } else {
                    html = html.replace("{mainIdInputContent}",
                            "<input type='hidden' id='mainId' name='mainId' value='<%= request.getParameter(\"mainId\")%>'>");
                }
            } else {
                boolean bool = (boolean) result_map.get("flag");
                if (bool) {
                    List<Model> subModelLst = (List<Model>) result_map.get("subModel");
                    Map<String, String> resMap = JspUtil.spellMainContent(model, operType, subModelLst, appLy);
                    html = html.replace("{mainContent}", resMap.get("mainHead"))
                            .replace("{mainEnd}", resMap.get("mainEnd"))
                            .replace("{mainJsContent}", resMap.get("mainJs"))
                            .replace("{mainIdInputContent}", "<input type='hidden' ng-model='mId'  id='mId'>");
                } else {
                    html = html.replace("{mainContent}", "")
                            .replace("{mainEnd}", "")
                            .replace("{mainJsContent}", "")
                            .replace("{mainIdInputContent}", "");
                }
            }
            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * <p>
     * TODO 拼写选择设置是否含有此项
     * </p>
     * <p>
     *
     * @param typeList <p>
     * @return </p>
     * @author : xiaoliu
     * @date :2017年6月28日下午7:38:46
     */
    public static String spellTypeSel(List<GenSelectType> typeList) {
        StringBuilder sb = new StringBuilder();
        if (typeList.size() > 0) {
            sb.append(" $SHOWCONTROL$ ");
        } else {
            sb.append("");
        }
        return sb.toString();
    }

    /**
     * <p>
     * TODO 返回是否必填标识
     * </p>
     * <p>
     *
     * @param model  <p>
     * @param isnull <p>
     * @return </p>
     * @author : xiaoliu
     * @date :2017年6月28日下午10:26:56
     */
    public static String spellSpanDitySel(Model model, int isnull, AttrGroup group, String type, String opaType,
                                          String ruleType) {
        StringBuilder sb = new StringBuilder();
        int isMoreView = model.getIsMoreView();// 是否多 视图
        if (isMoreView == 1) {// 是多视图
            if (group != null) {
                int isDefaultView = group.getIsDefaultView();// 是否默认视图
                if (isDefaultView == 1) {// 是认属性组
                    if (isnull == 0) {// 必填
                        sb.append(
                                "              <span style='color:red' ng-show='$TABLENAME$.$COLUMN$.$dirty && $TABLENAME$.$COLUMN$.$invalid'>$RN$");
                        sb.append("                   <span ng-show='$TABLENAME$.$COLUMN$.$error.required'>必填</span>$RN$");
                        if ("CLOB".equals(type)) {
                            sb.append(
                                    "         <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$MAXLEN$</span>$RN$");
                        } else if ("NUMBER".equals(type)) {
                            sb.append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.pattern'>只能输入数字</span>$RN$");
                            sb.append(
                                    "             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$MAXLEN$</span>$RN$");
                        } else if ("NUMBERM".equals(type)) {
                            sb.append(
                                    "             <span ng-show='$TABLENAME$.$COLUMN$.$error.pattern'>输入合理小数格式</span>$RN$");
                            sb.append(
                                    "             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$XLEN$</span>$RN$");
                        } else if ("VARCHAR2".equals(type)) {
                            if (ruleType.equals("0")) {
                                sb.append(
                                        "             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$MAXLEN$</span>$RN$");
                            } else if (ruleType.equals("1")) {
                                sb.append("              <span ng-show='$TABLENAME$.$COLUMN$.$error.email'>非邮箱格式</span>");
                            } else if (ruleType.equals("2")) {
                                sb.append(
                                        "             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$MAXLEN$</span>$RN$");
                            } else if (ruleType.equals("3")) {
                                sb.append(
                                        "             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$MAXLEN$</span>$RN$");
                            }
                        }
                        sb.append("                </span>$RN$");
                    } else if (isnull == 1) {// 不必填
                        sb.append("");
                    }
                } else if (isDefaultView == 0) {// 不是默认属性组
                    if (isnull == 0) {
                        sb.append("");
                    } else if (isnull == 1) {
                        sb.append("");
                    }
                }
            }
        } else if (isMoreView == 0) {// 不是多视图
            if (isnull == 0) {
                sb.append(
                        "              <span style='color:red' ng-show='$TABLENAME$.$COLUMN$.$dirty && $TABLENAME$.$COLUMN$.$invalid'>$RN$");
                sb.append("                   <span ng-show='$TABLENAME$.$COLUMN$.$error.required'>必填</span>$RN$");
                if ("CLOB".equals(type)) {
                    sb.append(
                            "         <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$MAXLEN$</span>$RN$");
                } else if ("NUMBER".equals(type)) {
                    sb.append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.pattern'>只能输入数字</span>$RN$");
                    sb.append(
                            "             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$MAXLEN$</span>$RN$");
                } else if ("NUMBERM".equals(type)) {
                    sb.append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.pattern'>输入合理小数格式</span>$RN$");
                    sb.append(
                            "             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>长度不超过$XLEN$</span>$RN$");
                }
                sb.append("                </span>$RN$");
            } else if (isnull == 1) {
                sb.append("");
            }
        }
        return sb.toString();
    }

    /**
     * <p>
     * TODO 是否引用下拉框模糊查询标签
     * </p>
     * <p>
     *
     * @param type    <p>
     * @param opaType <p>
     * @return </p>
     * @author : xiaoliu
     * @date :2017年6月28日下午10:44:02
     */
    public static String spellSelectSel(String type, String opaType) {
        StringBuilder sb = new StringBuilder();
        if ("selectList".equals(type)) {// 如果是下拉框
            if ("edit".equals(opaType) || "updateEdit".equals(opaType) || "treeTabEdit".equals(opaType)
                    || "treeTabUpdateEdit".equals(opaType)) {
                sb.append("select2");
            } else {
                sb.append("");
            }
        }
        return sb.toString();
    }

    public static String spellRequiredSel(Model model, int isnull, AttrGroup group) {
        StringBuilder sb = new StringBuilder();
        int isMoreView = model.getIsMoreView();// 是否多 视图
        if (isMoreView == 1) {// 是多视图
            if (group != null) {
                int isDefaultView = group.getIsDefaultView();// 是否默认视图
                if (isDefaultView == 1) {// 是认属性组
                    if (isnull == 0) {// 必填
                        sb.append("required");
                    } else if (isnull == 1) {// 不必填
                        sb.append("");
                    }
                }
            }
        } else if (isMoreView == 0) {// 不是多视图
            if (isnull == 0) {
                sb.append("required");
            } else if (isnull == 1) {
                sb.append("");
            }
        }
        return sb.toString();
    }

    public static String spellSpanFontSel(int isnull, String type) {
        StringBuilder sb = new StringBuilder();
        if (isnull == 0) {
            sb.append("           <div>$RN$");
            if (type.equals("popList")) {
                sb.append("              <button class='btn btn-primary' type='button' data-toggle='modal' ng-click='open$COLUMN$()'>选择</button>$RN$")
                        .append("              <button class='btn' type='button' ng-click='open$COLUMN$Clear()'>清空</button>$RN$");
                sb.append("              <span help-block m-b-none><font color='red'>*</font>必填</span>")
                        .append("                  <div class='modal fade' id='pop$COLUMN$' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>$RN$")
                        .append("                       <div class='modal-dialog'>$RN$")
                        .append("                            <div class='modal-content'>$RN$")
                        .append("                            </div>$RN$")
                        .append("                       </div>$RN$")
                        .append("                  </div>$RN$");
            } else if (type.equals("listTree")) {
                sb.append("          <button class='btn btn-primary' type='button' data-toggle='modal' ng-click='tree$COLUMN$()'>选择</button>$RN$")
                        .append("          <button class='btn' type='button' ng-click='tree$COLUMN$Clear()'>清空</button>$RN$")
                        .append("          <span help-block m-b-none><font color='red'>*</font>必填</span>")
                        .append("              <div class='modal fade' id='tree$COLUMN$' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>$RN$")
                        .append("                       <div class='modal-dialog'>$RN$")
                        .append("                            <div class='modal-content'>$RN$")
                        .append("                            </div>$RN$")
                        .append("                       </div>$RN$")
                        .append("              </div>$RN$");
            } else if ("CLOB".equals(type) || "NUMBERM".equals(type) || "NUMBER".equals(type)) {
                sb.append("	    <span help-block m-b-none><font color='red'>*</font>必填数字且超度不超过$MAXLEN$</span>$RN$");
            } else {
                sb.append("     <span class='help-block m-b-none'><font color='red'>*</font>必填</span>$RN$");

            }
            sb.append("           </div>$RN$");
        } else if (isnull == 1) {
            sb.append("           <div>$RN$");
            if (type.equals("popList")) {
                sb.append("              <button class='btn btn-primary' type='button' data-toggle='modal' ng-click='open$COLUMN$()'>选择</button>$RN$")
                        .append("              <button class='btn' type='button' ng-click='open$COLUMN$Clear()'>清空</button>$RN$");
                sb.append("                  <div class='modal fade' id='pop$COLUMN$' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>$RN$")
                        .append("                       <div class='modal-dialog'>$RN$")
                        .append("                            <div class='modal-content'>$RN$")
                        .append("                            </div>$RN$")
                        .append("                       </div>$RN$")
                        .append("                  </div>$RN$");
            } else if (type.equals("listTree")) {
                sb.append("          <button class='btn btn-primary' type='button' data-toggle='modal' ng-click='tree$COLUMN$()'>选择</button>$RN$")
                        .append("          <button class='btn' type='button' ng-click='tree$COLUMN$Clear()'>清空</button>$RN$")
                        .append("              <div class='modal fade' id='tree$COLUMN$' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>$RN$")
                        .append("                       <div class='modal-dialog'>$RN$")
                        .append("                            <div class='modal-content'>$RN$")
                        .append("                            </div>$RN$")
                        .append("                       </div>$RN$")
                        .append("              </div>$RN$");
            }
            sb.append("           </div>$RN$");
        }
        return sb.toString();
    }

    /**
     * <p>TODO 多视图新增页面</p>
     * <p>@param readFilePath
     * <p>@param model
     * <p>@param operType
     * <p>@param appLy
     * <p>@param result_map </p>
     *
     * @author : xiaoliu
     * @date :2017年6月30日上午10:27:15
     */
    public static void createTreeTabViewAddPage(String addStr, String readFilePath,
                                                Model model, String operType, String appLy, Map<String, Object> result_map,
                                                List<AttrGroup> groupLst, List<AttrConfig> configLst) {
        try {
            String jspTmpContent = JspUtil.getTmpJspContent(readFilePath); // 根据路径获取自动生成的模板内容
            String html = jspTmpContent.replace("{viewMainContentRep}", addStr); // 将占位符替换成拼接的内容
            html = html.replace("{shiroRep}", AddJspCreate.spellShiroRep(operType));
            html = html.replace("{linkRep}", AddJspCreate.spellLinkRep(operType));
            html = html.replace("{scriptRep}", AddJspCreate.spellScriptRep(operType));
            html = AddJspCreate.replaceTreeTabAddFormat(html, model, operType); // 格式化换行等占位符
            boolean bool = (boolean) result_map.get("flag");
            if (bool) {//说明有从表
                @SuppressWarnings("unchecked")
                List<Model> subModelLst = (List<Model>) result_map.get("subModel");
                Map<String, String> resMap = spellMainViewSubContent(model, result_map, operType, subModelLst, appLy, groupLst, configLst);
                html = html.replace("{viewSubContentRep}", resMap.get("viewSubContentRep"))
                        .replace("{viewGroupRep}", resMap.get("viewGroupRep"))
                        .replace("{navTabsRep}", resMap.get("navTabsRep"))
                        .replace("{mainJsContentRep}", resMap.get("mainJsContentRep"))
                        .replace("{mainIdInputRep}", "<input type='hidden' ng-model='mId'  id='mId'>");
            } else {
                Map<String, String> resMap = spellMainViewSubContent(model, result_map, operType, null, appLy, groupLst, configLst);
                html = html.replace("{viewSubContentRep}", "")
                        .replace("{viewGroupRep}", resMap.get("viewGroupRep"))
                        .replace("{navTabsRep}", resMap.get("navTabsRep"))
                        .replace("{mainJsContentRep}", "")
                        .replace("{mainIdInputRep}", "");
            }

            JspUtil.writeInJsp(html, readFilePath); // 将替换后的、正式的字符串重新写入生成的jsp里
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String spellShiroRep(String opaType) {
        StringBuilder sb = new StringBuilder();
        if ("treeTabAdd".equals(opaType)) {
            sb.append("");
        } else if ("treeTabEdit".equals(opaType)) {
            sb.append("");
        }
        return sb.toString();
    }

    public static String spellLinkRep(String opaType) {
        StringBuilder sb = new StringBuilder();
        if ("treeTabAdd".equals(opaType) || "add".equals(opaType)) {
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/hplus/bootstrap.min14ed.css?v=3.3.6\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/bootstrap/bootstrap.min.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/angular-ui-select2/select2.css\">");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/angular-ui-select2/select2-bootstrap.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/datapicker/datepicker3.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/hplus/animate.min.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/toastr/toastr.min.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/newAdd.css\"> $RN$ ");
        } else if ("treeTabEdit".equals(opaType) || "edit".equals(opaType)) {
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/hplus/bootstrap.min14ed.css?v=3.3.6\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/bootstrap/bootstrap.min.css\"> $RN$ ");
            //sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/angular-ui-select2/select2.css\"> $RN$ ");
            //sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/angular-ui-select2/select2-bootstrap.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/datapicker/datepicker3.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/hplus/animate.min.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/plugins/toastr/toastr.min.css\"> $RN$ ");
            sb.append("<link rel=\"stylesheet\" href=\"${basePath}/css/newAdd.css\"> $RN$ ");
        }

        return sb.toString().replace("$RN$", "\r\n");
    }


    public static String spellScriptRep(String opaType) {
        StringBuilder sb = new StringBuilder();
        sb.append("<script src=\"${basePath}/js/jquery/jquery.min.js?v=2.1.4\"></script> $RN$ ");
        sb.append("<script src=\"${basePath}/js/jquery/jquery.form.js\"></script> $RN$ ");
        sb.append("<script src=\"${basePath}/js/bootstrap-3.3.6/bootstrap.min.js?v=3.3.6\"></script> $RN$");
        sb.append("<script src=\"${basePath}/js/datapicker/bootstrap-datepicker.js\"></script> $RN$ ");
        sb.append("<script src=\"${basePath}/js/angular-ui-select2/select2.min.js\"></script> $RN$ ");
        sb.append("<script src=\"${basePath}/js/angular-1.4.6/angular.min.js\"></script> $RN$ ");
        sb.append("<script src=\"${basePath}/js/angular-1.4.6/angular-animate.min.js\"></script> $RN$ ");
        sb.append("<script src=\"${basePath}/js/angular-1.4.6/angular-animate.min.js\"></script> $RN$ ");
        sb.append("<script src=\"${basePath}/js/hplus/toastr.min.js\"></script> $RN$ ");
        sb.append("<script src=\"${basePath}/dm/js/common/kepdown.js\"></script> $RN$ ");
        return sb.toString().replace("$RN$", "\r\n");
    }


    public static Map<String, String> spellMainViewSubContent(Model mainModel, Map<String, Object> result_map, String operType, List<Model> subModelLst,
                                                              String backPage, List<AttrGroup> groupLst, List<AttrConfig> configLst) {

        StringBuilder viewGroupRep = new StringBuilder();//视图列表替换
        StringBuilder navTabsRep = new StringBuilder();//多tab页替换
        StringBuilder viewSubContentRep = new StringBuilder();//多视图属性内容替换
        StringBuilder mainJsContentRep = new StringBuilder();//跳转从表替换

        //1.拼写视图列表替换
        viewGroupRep.append(AddJspCreate.spellViewSubRep(mainModel, groupLst));
        //2.拼写多tab页替换
        navTabsRep.append(AddJspCreate.spellViewNavTabsRep(mainModel, groupLst, configLst, subModelLst, operType, backPage));
        //3.viewSubContentRep多视图属性替换方法
        viewSubContentRep.append(AddJspCreate.spellViewSubContentRep(mainModel, subModelLst, operType, backPage));
        //4.主从表关系，从表
        mainJsContentRep.append(AddJspCreate.spellViewNavSubsRep(mainModel, subModelLst, operType, backPage));

        Map<String, String> res_map = new HashMap<String, String>();

        res_map.put("viewGroupRep", viewGroupRep.toString().replace("$RN$", "\r\n"));
        res_map.put("navTabsRep", navTabsRep.toString().replace("$RN$", "\r\n"));
        res_map.put("viewSubContentRep", viewSubContentRep.toString().replace("$RN$", "\r\n"));
        res_map.put("mainJsContentRep", mainJsContentRep.toString().replace("$RN$", "\r\n"));

        return res_map;
    }

    //含有从表的多视图
    public static String spellViewSubRep(Model model, List<AttrGroup> groupLst) {
        StringBuilder sb = new StringBuilder();//视图列表替换
        if (groupLst.size() > 0) {//如果有视图设置
            sb.append(" <div class='form-group draggable' >\r\n");
            sb.append("      <label class='col-sm-1 control-label' align='left'>视图列表</label>\r\n");
            sb.append("      <div class='col-sm-8' >    \r\n");
            for (int i = 0; i < groupLst.size(); i++) {
                AttrGroup attrGroup = groupLst.get(i);
                String groupID = attrGroup.getId();// 获取groupID
                String groupName = attrGroup.getGroupName();// 获取属性组名称
                if (attrGroup.getIsDefaultView() == 1) {// 是默认视图---默认选中且不可编辑
                    sb.append("          <label class='checkbox-inline control-label'  >\r\n");
                    sb.append("                <input type='checkbox'  checked='checked'  disabled='disabled'   id='"
                            + model.getTableName() + "_" + groupID + "'  >");
                    sb.append(groupName);
                    sb.append("          </label>        \r\n");
                } else {// 不是默认视图
                    sb.append("          <label class='checkbox-inline control-label'  >\r\n");
                    sb.append("                  <input type='checkbox'   id='" + model.getTableName() + "_" + groupID
                            + "'  ng-click='check_" + model.getTableName() + "_" + groupID + "_Check()'>");
                    sb.append(groupName);
                    sb.append("          </label>        \r\n");
                }
            }
            sb.append("      </div>\r\n");
            sb.append("  </div>\r\n");
        }
        return sb.toString();
    }

    public static String spellViewNavTabsRep(Model model, List<AttrGroup> groupLst, List<AttrConfig> configLst, List<Model> subModelLst, String operType, String backPage) {
        StringBuilder sb = new StringBuilder();//视图列表替换
        List<AttrConfig> jspAttrLst = new ArrayList<AttrConfig>();
        sb.append("           <ul id='myTab' class='nav nav-tabs'> $RN$");
        if (configLst.size() > 0) {
            for (AttrConfig attrConfig : configLst) {
                if (attrConfig.getGroupId() == null) {
                    if (attrConfig.getShowPage().contains("2")) { // 在对应的页面显示
                        jspAttrLst.add(attrConfig);
                    }
                }
            }
        }
        if (jspAttrLst.size() > 0) {//含有基本视图
            sb.append("                <li class='active'> $RN$");
            sb.append("                    <a href='#main' data-toggle='tab'> $RN$");
            sb.append("基本视图   $RN$");
            sb.append("                   </a> $RN$");
            sb.append("               </li> $RN$");

            if (groupLst.size() > 0) {//视图设置不为空
                for (int i = 0; i < groupLst.size(); i++) {
                    AttrGroup attrGroup = groupLst.get(i);
                    String groupID = attrGroup.getId();// 获取groupID
                    String groupName = attrGroup.getGroupName();
                    sb.append("           <li> $RN$");
                    sb.append("                <a href='#" + model.getTableName() + "_" + groupID + "_tab' data-toggle='tab' ng-show='" + model.getTableName() + "_" + groupID + "'> $RN$");
                    sb.append(groupName + " $RN$");
                    sb.append("                </a> $RN$");
                    sb.append("          </li> $RN$");
                }
            }
        } else {
            if (groupLst.size() > 0) {//视图设置不为空
                AttrGroup group = groupLst.get(0);
                String gID = group.getId();// 获取groupID
                String gName = group.getGroupName();
                sb.append("           <li class='active' > $RN$");
                sb.append("                <a href='#" + model.getTableName() + "_" + gID + "_tab' data-toggle='tab' > $RN$");
                sb.append(gName + " $RN$");
                sb.append("                </a> $RN$");
                sb.append("          </li> $RN$");

                for (int i = 1; i < groupLst.size(); i++) {
                    AttrGroup attrGroup = groupLst.get(i);
                    String groupID = attrGroup.getId();// 获取groupID
                    String groupName = attrGroup.getGroupName();
                    sb.append("           <li> $RN$");
                    sb.append("                <a href='#" + model.getTableName() + "_" + groupID + "_tab' data-toggle='tab'ng-show='" + model.getTableName() + "_" + groupID + "'> $RN$");
                    sb.append(groupName + " $RN$");
                    sb.append("                </a> $RN$");
                    sb.append("          </li> $RN$");
                }
            }
        }
        if (subModelLst != null) {
            if (subModelLst.size() > 0) {//如果存在从表
                for (int i = 0; i < subModelLst.size(); i++) {
                    Model subModel = subModelLst.get(i);
                    sb.append("           <li> $RN$");
                    sb.append("                <a href='#" + subModel.getTableName() + "' data-toggle='tab'> $RN$");
                    sb.append(subModel.getModelName() + " $RN$");
                    sb.append("                </a> $RN$");
                    sb.append("          </li> $RN$");
                }
            } else {
                sb.append("         $RN$");
            }
        }
        sb.append("          </ul> $RN$");
        return sb.toString();
    }

    public static String spellViewSubContentRep(Model model, List<Model> subModelLst, String operType, String backPage) {
        StringBuilder sb = new StringBuilder();//视图列表替换
        if (subModelLst != null) {
            if (subModelLst.size() > 0) {
                for (int i = 0; i < subModelLst.size(); i++) {
                    Model subModel = subModelLst.get(i);
                    sb.append("   <div class='tab-pane fade' id='" + subModel.getTableName() + "'> $RN$");
                    sb.append("         <iframe id='" + subModel.getTableName() + operType + "Frame' name='" + subModel.getTableName() + operType + "Frame' frameborder='0'  width='100%'> $RN$");
                    sb.append("         </iframe> $RN$");
                    sb.append("   </div> $RN$");
                }
            }
        }

        return sb.toString();
    }

    public static String spellViewNavSubsRep(Model model, List<Model> subModelLst, String operType, String backPage) {
        StringBuilder sb = new StringBuilder();//视图列表替换
        if (subModelLst != null) {
            if (subModelLst.size() > 0) {
                for (int i = 0; i < subModelLst.size(); i++) {
                    Model subModel = subModelLst.get(i);
                    sb.append("       $('#" + subModel.getTableName() + operType + "Frame').height($(window).height()); $RN$");
                    if ("add".equals(operType)) {
                        sb.append("       $('#" + subModel.getTableName() + operType + "Frame').attr('src'," + "basePath+" + "'/am/" + subModel.getTableName() + "/" + subModel.getTableName() + "_" + backPage + ".jsp'); $RN$");
                    } else if ("treeTabAdd".equals(operType)) {
                        sb.append("       $('#" + subModel.getTableName() + operType + "Frame').attr('src'," + "basePath+" + "'/am/" + subModel.getTableName() + "/" + subModel.getTableName() + "_apply.jsp'); $RN$");
                    } else if ("edit".equals(operType) || "updateEdit".equals(operType)) {
                        sb.append("       $('#" + subModel.getTableName() + operType + "Frame').attr('src'," + "basePath+" + "'/am/" + subModel.getTableName() + "/" + subModel.getTableName() + "_" + backPage + ".jsp?mainId='+$('#id').val()); $RN$");
                    } else if ("treeTabEdit".equals(operType)) {
                        sb.append("       $('#" + subModel.getTableName() + operType + "Frame').attr('src'," + "basePath+" + "'/am/" + subModel.getTableName() + "/" + subModel.getTableName() + "_apply.jsp?mainId='+$('#id').val()); $RN$");
                    } else if ("treeTabUpdateEdit".equals(operType)) {
                        sb.append("       $('#" + subModel.getTableName() + operType + "Frame').attr('src'," + "basePath+" + "'/am/" + subModel.getTableName() + "/" + subModel.getTableName() + "_update.jsp?mainId='+$('#id').val()); $RN$");
                    } else {
                        //刘晶，动态生成查看详情模块替换
                        sb.append("   $('#" + subModel.getTableName() + operType + "Frame').attr('src'," + "basePath+" + "'/am/" + subModel.getTableName() + "/" + subModel.getTableName() + "_" + "'+styleOp+'" + "Detail.jsp?mainId='+id+'&style='+style); $RN$");
                    }
                }
            }
        }

        return sb.toString();
    }


    //拼写单选按钮的生成页面呢
    public static String spellRadio(Model model, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        sb.append("            <div class='form-group draggable' id='$column$Div' ");
        if (showControl != null) {// 说明是选择设置
            sb.append(" $SHOWCONTROL$ ").append(">$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("                   <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$");
        sb.append("                        <div class='col-sm-5' >$RN$");
//					{{$COLUMN$.name}}   单选框生成页面报错的问题
        sb.append("                            <label class='radio-inline' ng-repeat='$COLUMN$ in $COLUMN$s'>");
        sb.append("                               <input type='radio' id='$COLUMN$' name='$COLUMN$' ng-model='$parent.$COLUMN$' "
                + "value='{{$COLUMN$.value}}' ng-change='input$COLUMN$ValueIsChanged(\"$COLUMN$\"+{{$COLUMN$.value}})'>{{$COLUMN$.name}}");
        sb.append("                            </label>$RN$");
        sb.append("                        </div>$RN$");
        if (isnull == 0) {//必填
            sb.append("                        <div>$RN$");
            sb.append("                              <span class='help-block m-b-none'><font color='red'>*</font>$ATTRNAME$必填</span>$RN$");
            sb.append("                        </div>$RN$ ");
        }
        sb.append("           </div>$RN$");
        return sb.toString();
    }

    //拼写复选框的生成页面呢
    public static String spellCheckBox(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        sb.append("                 <div class='form-group draggable' id='$COLUMN$Div' ");
        if (showControl != null) {// 属性类型为单选按钮，组件类型为单选设置类型解决问题如下
            sb.append(" $SHOWCONTROL$").append(" >$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("                  <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$");
        sb.append("                       <div class='col-sm-5' >$RN$");
        sb.append("                            <label class='checkbox-inline' ng-repeat='$COLUMN$ in $COLUMN$s'>$RN$");
        if ("edit".equals(opaType) || "updateEdit".equals(opaType)
                || "treeTabEdit".equals(opaType) || "treeTabUpdateEdit".equals(opaType)) {
            sb.append("                            <input type='checkbox'  name='$COLUMN$' id='$COLUMN${{$COLUMN$.value}}'  value='{{$COLUMN$.value}}'>$RN$");
            sb.append("               {{$COLUMN$.name}}");
        } else {
            sb.append("                            <input type='checkbox' id='$COLUMN${{$COLUMN$.value}}'  value='{{$COLUMN$.value}}'"
                    + " name='$COLUMN$' ng-model='$parent.$COLUMN$[$index]'  >{{$COLUMN$.name}}");
        }
        sb.append("                          </label>$RN$");
        sb.append("                      </div>$RN$");
        if (isnull == 0) {//必填
            sb.append("                  <div>$RN$");
            sb.append("                       <span class='help-block m-b-none'><font color='red'>*</font>$ATTRNAME$必填</span>$RN$");
            sb.append("                  </div>$RN$ ");
        }
        sb.append("           </div>$RN$");

        return sb.toString();
    }

    //拼写下拉框
    public static String spellSelectList(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        String column = attrConfig.getAttrColumn().toLowerCase(); // 字段名
        int isnull = attrConfig.getIsNull();
        sb.append("    <div class='form-group draggable' id='$COLUMN$Div' ");
        if (showControl != null) {// 属性类型是下拉框，组件是选择设置
            sb.append(" $SHOWCONTROL$ ").append(">$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("     <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$");
        sb.append("     <div class='col-sm-5' >$RN$");
        sb.append("          <select select2 class='form-control' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' "
                + "ng-change='selClick$COLUMN$()'>$RN$");
//				  if(isnull==0){//若是必填--不需要请选择
//					  if ("edit".equals(opaType) || "updateEdit".equals(opaType)
//								|| "treeTabEdit".equals(opaType) || "treeTabUpdateEdit".equals(opaType)) {
//							sb.append("       <option ng-repeat='"+ column.split("_")[0] +" in $COLUMN$s' value='{{"
//								+ column.split("_")[0] +".value}}'  ng-selected='{{$COLUMN$=="
//								+ column.split("_")[0] +".value}}'>{{"+ column.split("_")[0] +".name}}</option>$RN$");
//						} else {
//							 sb.append("     <option ng-repeat='$COLUMN$ in $COLUMN$s' value='{{$COLUMN$.value}}'>{{$COLUMN$.name}}</option>$RN$");
//						}
//				  }else{//不是必填项，添加一列请选择
        if ("edit".equals(opaType) || "updateEdit".equals(opaType)
                || "treeTabEdit".equals(opaType) || "treeTabUpdateEdit".equals(opaType)) {
            sb.append("          <option value=''>请选择</option>$RN$");
            sb.append("       <option ng-repeat='" + column.split("_")[0] + " in $COLUMN$s' value='{{"
                    + column.split("_")[0] + ".value}}'  ng-selected='{{$COLUMN$=="
                    + column.split("_")[0] + ".value}}'>{{" + column.split("_")[0] + ".name}}</option>$RN$");
        } else {
            sb.append("          <option value=''>请选择</option>$RN$");
            sb.append("     <option ng-repeat='$COLUMN$ in $COLUMN$s' value='{{$COLUMN$.value}}'>{{$COLUMN$.name}}</option>$RN$");
        }

//				  }
        sb.append("              </select>$RN$");
        sb.append("      </div>$RN$");
        if (isnull == 0) {//必填
            sb.append("     <div>$RN$");
            sb.append("          <span class='help-block m-b-none'><font color='red'>*</font>$ATTRNAME$必填</span>$RN$");
            sb.append("     </div>$RN$ ");
        }
        sb.append("   </div>$RN$");
        return sb.toString();
    }

    //拼写date格式的页面日期拼写
    public static String spellDate(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        sb.append("        <div class='form-group draggable' ");
        if (showControl != null) {
            sb.append(" $SHOWCONTROL$ ").append(" >$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("         <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$");
        sb.append("               <div class='col-sm-5' >$RN$");
        sb.append("                    <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' readonly>$RN$");
        sb.append("               </div>$RN$");
        if (isnull == 0) {//表示必填
            sb.append("          <div>$RN$");
            sb.append("               <span class='help-block m-b-none'><font color='red'>*</font>$ATTRNAME$必填</span>$RN$");
            sb.append("          </div>$RN$ ");
        }
        sb.append("   </div>$RN$");

        return sb.toString();
    }

    //拼写弹出框页面popList
    public static String spellPopList(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        sb.append("     <div class='form-group draggable'");
        if (showControl != null) {
            sb.append("   $SHOWCONTROL$ ").append("   >$RN$");
        } else {
            sb.append("   >$RN$");
        }
        if (attrConfig.getModuleType().equals("5")) {//非动态模型，外部选择数据表
            sb.append("     <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$")
                    .append("         <div class='col-sm-5' >$RN$")
                    .append("             <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' readonly>$RN$")
                    .append("         </div>$RN$");
        } else {
            sb.append("     <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$")
                    .append("         <div class='col-sm-5' >$RN$")
                    .append("             <input type='text' id='$COLUMN$Name' class='form-control' readonly>$RN$")
                    .append("             <input type='hidden' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'>$RN$")
                    .append("         </div>$RN$");
        }


        sb.append("        <div>$RN$")
                .append("              <button class='btn btn-primary' type='button' data-toggle='modal' ng-click='open$COLUMN$()'>选择</button>$RN$")
                .append("              <button class='btn' type='button' ng-click='open$COLUMN$Clear()'>清空</button>$RN$");
        if (isnull == 0) {//必填
            sb.append("           <span help-block m-b-none><font color='red'>*</font>$ATTRNAME$必填</span>$RN$");
        }
        sb.append("             <div class='modal fade' id='pop$COLUMN$' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>$RN$")
                .append("                <div class='modal-dialog'>$RN$")
                .append("                    <div class='modal-content'>$RN$")
                .append("                    </div>$RN$")
                .append("                </div>$RN$")
                .append("            </div>$RN$")
                .append("       </div>$RN$");
        sb.append("  </div>$RN$");

        return sb.toString();

    }

    //拼写是列表树的页面的方法（新增，修改，编辑）
    public static String spellListTree(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        sb.append("  <div class='form-group draggable'");
        if (showControl != null) {
            sb.append("$SHOWCONTROL$").append(">$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("   <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$")
                .append("      <div class='col-sm-5' >$RN$")
                .append("          <input type='text' id='$COLUMN$Name'  name='$COLUMN$Name' ng-model='$COLUMN$Name' class='form-control' readonly>$RN$")
                .append("          <input type='hidden' id='$COLUMN$'  name='$COLUMN$' ng-model='$COLUMN$'  class='form-control'>$RN$")
                .append("      </div>$RN$")
                .append("      <div>$RN$")
                .append("          <button class='btn btn-primary' type='button' data-toggle='modal' ng-click='tree$COLUMN$()'>选择</button>$RN$")
                .append("          <button class='btn' type='button' ng-click='tree$COLUMN$Clear()'>清空</button>$RN$");
        if (isnull == 0) {//必填
            sb.append("          <span help-block m-b-none><font color='red'>*</font>$ATTRNAME$必填</span>$RN$");
        }
        sb.append("         <div class='modal fade' id='tree$COLUMN$' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>$RN$")
                .append("             <div class='modal-dialog'>$RN$")
                .append("                 <div class='modal-content'>$RN$")
                .append("                 </div>$RN$")
                .append("             </div>$RN$")
                .append("         </div>$RN$")
                .append("     </div>$RN$");
        sb.append("  </div>$RN$");

        return sb.toString();
    }

    //拼写blob 文件格式，file 页面拼写方法
    public static String spellBloB(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();

        sb.append("  <div class='form-group draggable' id='$COLUMN$Div' ");
        if (showControl != null) {
            sb.append("$SHOWCONTROL$").append(">$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("   <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$")
                .append("   <div class='col-sm-5' >$RN$")
                .append("       <input type='file' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' >$RN$")
                .append("   </div>$RN$")
                .append("   <div>$RN$")
                .append("      <button type='button' id='$COLUMN$Button' class='btn btn-outline btn-default' ng-click='addButtons(\"$COLUMN$\")'>$RN$")
                .append("          添加$RN$")
                .append("      </button>$RN$");
        if (isnull == 0) {//必填
            sb.append("          <span help-block m-b-none><font color='red'>*</font>$ATTRNAME$必填</span>$RN$");
        }
        sb.append("      <span  id='fileName$COLUMN$' ></span>$RN$")
                .append("   </div>$RN$")
                .append(" </div>$RN$")
                .append(" <div id='$COLUMN$files'>$RN$")
                .append(" </div>$RN$");
        return sb.toString();
    }

    //拼写多文本框clob
    public static String spellCloB(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        sb.append("   <div class='form-group draggable' id='$COLUMN$Div' ");
        if (showControl != null) {
            sb.append("$SHOWCONTROL$").append(">$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("    <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$")
                .append("    <div class='col-sm-5' >$RN$")
                .append("        <textarea rows='5' cols='20' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' ng-maxlength='$MAXLEN$'>$RN$")
                .append("        </textarea>$RN$");
        if (isnull == 0) {
            sb.append("       <span style='color:red' ng-show='$TABLENAME$.$COLUMN$.$dirty && $TABLENAME$.$COLUMN$.$invalid'>$RN$")
//				  .append("         <span ng-show='$TABLENAME$.$COLUMN$.$error.required'>$ATTRNAME$必填</span>$RN$")
                    .append("         <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>$ATTRNAME$长度不超过$MAXLEN$</span>$RN$")
                    .append("       </span>$RN$");
        }
        sb.append("    </div>$RN$");
        if (isnull == 0) {//必填
            sb.append("   <div>$RN$")
                    .append("      <span help-block m-b-none><font color='red'>*</font>$ATTRNAME$必填且长度不超过$MAXLEN$</span>$RN$")
                    .append("   </div>$RN$");
        }
        sb.append("  </div>$RN$");
        return sb.toString();
    }

    //整数格式
    public static String spellNumber(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        sb.append("   <div class='form-group draggable' id='$COLUMN$Div' ");
        if (showControl != null) {
            sb.append("$SHOWCONTROL$").append(" >$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("      <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$")
                .append("      <div class='col-sm-5' >$RN$");
        if (showControl != null) {
            sb.append("          <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' "
                    + "ng-pattern='/^[1-9]+[0-9]*$/' ng-maxlength='$MAXLEN$'>$RN$");
            sb.append("          <span style='color:red' >$RN$")
                    .append("              <span ng-show='$TABLENAME$.$COLUMN$.$error.pattern'>只能输入数字</span>$RN$")
                    .append("              <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>$ATTRNAME$长度不超过$MAXLEN$</span>$RN$")
                    .append("          </span>$RN$");
        } else {
//					if(isnull==0){
//						sb.append("          <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' required "
//								+ " ng-pattern='/^[1-9]+[0-9]*$/' ng-maxlength='$MAXLEN$'>$RN$");
//						sb.append("          <span style='color:red' ng-show='$TABLENAME$.$COLUMN$.$dirty && $TABLENAME$.$COLUMN$.$invalid'>$RN$")
//						  .append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.required'>$ATTRNAME$必填</span>$RN$")
//						  .append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.pattern'>只能输入数字</span>$RN$")
//						  .append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>$ATTRNAME$长度不超过$MAXLEN$</span>$RN$")
//						  .append("          </span>$RN$");
//					}else{
            sb.append("          <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' "
                    + "  ng-pattern='/^[1-9]+[0-9]*$/' ng-maxlength='$MAXLEN$'>$RN$");
            sb.append("          <span style='color:red' ng-show='$TABLENAME$.$COLUMN$.$dirty && $TABLENAME$.$COLUMN$.$invalid'>$RN$")
                    .append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.pattern'>只能输入数字</span>$RN$")
                    .append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>$ATTRNAME$长度不超过$MAXLEN$</span>$RN$")
                    .append("          </span>$RN$");
//					}
        }
        sb.append("      </div>$RN$");
        if (isnull == 0) {
            sb.append("  <div>$RN$")
                    .append("	    <span help-block m-b-none><font color='red'>*</font>$ATTRNAME$必填数字且超度不超过$MAXLEN$</span>$RN$")
                    .append("  </div>$RN$");
        }
        sb.append("  </div>$RN$");
        return sb.toString();
    }

    //小数生成页面的方法
    public static String spellNumberm(Model model, String opaType, AttrConfig attrConfig, String showControl) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        sb.append("   <div class='form-group draggable' id='$COLUMN$Div' ");
        if (showControl != null) {
            sb.append("$SHOWCONTROL$").append(">$RN$");
        } else {
            sb.append(">$RN$");
        }
        sb.append("      <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$")
                .append("      <div class='col-sm-5' >$RN$");
//				if(isnull==0 && showControl!=null){
        sb.append("          <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' "
                + " ng-change='check$COLUMN$Number($COLUMN$)' class='form-control' ng-pattern='/^[0-9]+(\\.[0-9]+)?$/' ng-maxlength='$XLEN$'>$RN$");
//				}else{
//					sb.append("          <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' "
//							+ " ng-change='check$COLUMN$Number($COLUMN$)' class='form-control' ng-pattern='/^[0-9]+(\\.[0-9]+)?$/' ng-maxlength='$XLEN$'>$RN$");
//				}
        sb.append("          <span help-block m-b-none><font color='red'>*</font>$RN$");
//				if(showControl!=null && isnull == 0){
//					 sb.append("             <span ng-show='$TABLENAME$.$COLUMN$.$error.required'>$ATTRNAME$必填</span>$RN$");
//				}
        sb.append("              <span ng-show='$TABLENAME$.$COLUMN$.$error.pattern'>输入合理小数格式</span>$RN$")
                .append("              <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>$ATTRNAME$长度不超过$XLEN$</span>$RN$");
        sb.append("           </span>$RN$");
        sb.append("      </div>$RN$");
        if (isnull == 0) {
            sb.append("  <div>$RN$")
                    .append("	    <span help-block m-b-none><font color='red'>*</font>$ATTRNAME$必填数字且超度不超过$MAXLEN$</span>$RN$")
                    .append("  </div>$RN$");
        }
        sb.append("</div>$RN$");
        return sb.toString();
    }

    //拼写字符串的页面实现方法
    public static String spellVarchar(Model model, String opaType, AttrConfig attrConfig, String showControl, CheckRule checkRule) {
        StringBuilder sb = new StringBuilder();
        int isnull = attrConfig.getIsNull();
        //获取规则类型
        String ruleType = attrConfig.getRuleType();
        //规则校验id
        String ruleTypeId = attrConfig.getRuleTypeId();
        String checkRuleExpress = "";
        if (ruleTypeId != null) {
            checkRuleExpress = checkRule.getRule_express();//正则表达式
        }
        //如果是编码
        if ("4".equals(attrConfig.getModuleType())) {
            //这是审核完成后操作
            if ("updateEdit".equals(opaType) || "treeTabUpdateEdit".equals(opaType)) {//如果是变更编辑
                sb.append("    <div class='form-group draggable' ");
                if (showControl != null) {//有选择设置项
                    sb.append("$SHOWCONTROL$").append(" >$RN$");
                } else {
                    sb.append("  </div>$RN$");
                }
                sb.append("        <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$")
                        .append("        <div class='col-sm-5' >$RN$")
                        .append("            <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' readOnly >$RN$")
                        .append("            <input type='hidden' id='$COLUMN$_hidden' name='$COLUMN$_hidden' ng-model='$COLUMN$_hidden' />$RN$");
                sb.append("        </div> $RN$");
                if (isnull == 0) {
                    sb.append("  <div>$RN$")
                            .append("	    <span help-block m-b-none><font color='red'>*</font>$ATTRNAME$必填数字且超度不超过$MAXLEN$</span>$RN$")
                            .append("  </div>$RN$");
                }
                sb.append("    </div> $RN$");
            }
        } else {
            sb.append("      <div class='form-group draggable' ");
            if (showControl != null) {
                sb.append("$SHOWCONTROL$").append(">$RN$");
            } else {
                sb.append(">$RN$");
            }
            sb.append("         <label class='col-sm-3 control-label'>$ATTRNAME$</label>$RN$");
            sb.append("           <div class='col-sm-5' >$RN$");
            if (showControl != null && isnull == 0) {
                if (ruleType != null) {//如果校验类型不为空
                    if (ruleType.equals("0")) {//表示是校验唯一
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$'>$RN$");
                    } else if (ruleType.equals("1")) {//电子邮件校验
                        sb.append("         <input type='email' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'  ng-maxlength='$MAXLEN$' ng-pattern='" + checkRuleExpress + "'>$RN$");
                    } else if (ruleType.equals("2")) {//手机号码
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'  ng-maxlength='$MAXLEN$' ng-pattern='" + checkRuleExpress + "' >$RN$");
                    } else if (ruleType.equals("3")) {//座机号码
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$' ng-pattern='" + checkRuleExpress + "'>$RN$");
                    } else if (ruleType.equals("4")) {//邮政编码校验
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$' ng-pattern='" + checkRuleExpress + "'>$RN$");
                    } else {
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$'>$RN$");
                    }
                } else {
                    //生成的文本框是只读格式
                    if ("6".equals(attrConfig.getModuleType())) {
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'  readonly  ng-maxlength='$MAXLEN$'>$RN$");
                    } else {//普通必填文本框
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$'>$RN$");
                    }
                }
                sb.append("         <span style='color:red' ng-show='$TABLENAME$.$COLUMN$.$dirty && $TABLENAME$.$COLUMN$.$invalid'>$RN$");
//							 sb.append("            <span ng-show='$TABLENAME$.$COLUMN$.$error.required'>$ATTRNAME$必填</span>$RN$");
                sb.append("            <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>$ATTRNAME$长度不超过$MAXLEN$</span>$RN$");
                if (ruleType != null && ruleType.equals("1")) {
                    sb.append("        <span ng-show='$TABLENAME$.$COLUMN$.$error.email'>非邮箱格式</span>$RN$");
                }
                sb.append("        </span>$RN$");
            } else {
                if (ruleType != null) {//如果校验类型不为空
                    if (ruleType.equals("0")) {//表示是校验唯一
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'  ng-maxlength='$MAXLEN$'>$RN$");
                    } else if (ruleType.equals("1")) {//电子邮件校验
                        sb.append("         <input type='email' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control' ng-maxlength='$MAXLEN$'  ng-pattern='" + checkRuleExpress + "'>$RN$");
                    } else if (ruleType.equals("2")) {//手机号码
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'  ng-maxlength='$MAXLEN$' ng-pattern='" + checkRuleExpress + "' >$RN$");
                    } else if (ruleType.equals("3")) {//座机号码
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$' ng-pattern='" + checkRuleExpress + "'>$RN$");
                    } else if (ruleType.equals("4")) {//邮政编码校验
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$' ng-pattern='" + checkRuleExpress + "'>$RN$");
                    } else {
                        //sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$'>$RN$");
                        //生成的文本框是只读格式
                        if ("6".equals(attrConfig.getModuleType())) {
                            sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'  readonly  ng-maxlength='$MAXLEN$'>$RN$");
                        } else {//普通必填文本框
                            sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$'>$RN$");
                        }
                    }
                } else {
                    if ("6".equals(attrConfig.getModuleType())) {
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'  readonly  ng-maxlength='$MAXLEN$'>$RN$");
                    } else {//普通必填文本框
                        sb.append("         <input type='text' id='$COLUMN$' name='$COLUMN$' ng-model='$COLUMN$' class='form-control'   ng-maxlength='$MAXLEN$'>$RN$");
                    }
                }
                sb.append("         <span style='color:red' ng-show='$TABLENAME$.$COLUMN$.$dirty && $TABLENAME$.$COLUMN$.$invalid'>$RN$");
                sb.append("            <span ng-show='$TABLENAME$.$COLUMN$.$error.maxlength'>$ATTRNAME$长度不超过$MAXLEN$</span>$RN$");
                if (ruleType != null && ruleType.equals("1")) {
                    sb.append("        <span ng-show='$TABLENAME$.$COLUMN$.$error.email'>非邮箱格式</span>$RN$");
                }
                sb.append("        </span>$RN$");
            }
            sb.append("           </div>$RN$");
            if (isnull == 0) {
                sb.append("      <div>$RN$");
                sb.append("        <span help-block m-b-none><font color='red'>*</font>$ATTRNAME$必填且长度不超过$MAXLEN$</span>$RN$");
                sb.append("      </div>$RN$");
            }
            sb.append("        </div>$RN$");
        }
        return sb.toString();
    }

}
